home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / DEVEL2.ZIP / POINTER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-16  |  1.8 KB  |  68 lines

  1. /* Abstract pointer routine */
  2.  
  3. /* Written by Bernie Roehl, February 1992 */
  4.  
  5. /* The idea is that you have a pointing device with (up to) 6 degrees of
  6.    freedom and (at least) two buttons */
  7.  
  8. /* There will be one of these modules for each possible pointing device;
  9.    you link in the one you're using */
  10.  
  11. /* Eventually this should be a TSR, and you just call down to it (similar
  12.    to how a mouse driver works) */
  13.    
  14. /* This version reads the mouse; if the right-hand button is down,
  15.    vertical  motion gets mapped to forward/backward */
  16.  
  17. #include <stdio.h>
  18. #include <dos.h>
  19. #include "pointer.h"
  20.  
  21. pointer_init(int port, POINTER *pointer)
  22.     {
  23.     union REGS r;
  24.     int i;
  25.     pointer->port = port;
  26.     pointer->gesture = pointer->buttons = 0;
  27.     pointer->x = pointer->y = pointer->z = 0;
  28.     pointer->pan = pointer->tilt = pointer->roll = 0;
  29.     pointer->sx = pointer->sy = pointer->sz = 1;
  30.     for (i = 0; i < 16; ++i) pointer->flex[i] = 0;
  31.     r.x.ax = 0;
  32.     int86(0x33, &r, &r);
  33.     return r.x.ax;    
  34.     }
  35.  
  36. pointer_read(POINTER *pointer)
  37.     {
  38.     union REGS r;
  39.     unsigned oldbutt;
  40.     oldbutt = pointer->buttons;
  41.     r.x.ax = 3;  /* read button status */
  42.     int86(0x33, &r, &r);
  43.     pointer->buttons = r.x.bx;
  44.     r.x.ax = 11;  /* read motion counters */
  45.     int86(0x33, &r, &r);
  46.     pointer->x += ((int) r.x.cx) * pointer->sx;
  47.     if (pointer->buttons & 0x02)
  48.         pointer->z -= ((int) r.x.dx) * pointer->sy;
  49.     else
  50.         pointer->y -= ((int) r.x.dx) * pointer->sz;
  51.     pointer->buttons &= 0x01;
  52.     return r.x.dx | r.x.cx | (pointer->buttons ^ oldbutt);  /* return non-zero if changed */
  53.     }
  54.  
  55. void pointer_scale(POINTER *pointer, long sx, long sy, long sz)
  56.     {
  57.     pointer->sx = sx; pointer->sy = sy; pointer->sz = sz;
  58.     }
  59.  
  60. void pointer_move(POINTER *pointer, long x, long y, long z)
  61.     {
  62.     pointer->x = x;  pointer->y = y;  pointer->z = z;
  63.     }
  64.  
  65. void pointer_quit(POINTER *pointer)
  66.     {
  67.     }
  68.